<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            border: 1px solid #000;
            margin: 100px auto;
        }

        .box input {
            width: 170px;
            height: 30px;
            padding-left: 10px;
            margin: 15px 10px 15px 10px;
            border-radius: 5px;
            border: 1px solid gray;
        }

        .box button {
            width: 180px;
            height: 30px;
            border-radius: 10px;
            background-color: cornflowerblue;
            text-align: center;
            cursor: pointer;
            margin-top: 20px;
            margin-left: 10px;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="text" placeholder="手机号/用户名/邮箱">
        <input type="password" placeholder="密码">
        <button>登录</button>
    </div>
</body>

</html>
<script src="promise-ajax函数.js"></script>
<script>
    let inputs = document.querySelectorAll('input')
    let btn = document.querySelector('button')
    btn.onclick = function () {
        if (inputs[0].value && inputs[1].value) {
            if (/^\d{4}$/.test(inputs[1].value)) {
                ajax('get', 'https://yantianfeng.com/api/login', { username: inputs[0].value, password: inputs[1].value }).then((data) => {
                 alert(data.msg)
                })

            } else {
                alert('请输入正确得手机号/密码')
            }
        } else {
            alert('手机号/密码不能为空')
        }
    }
</script>